<template>
  <div>
    <el-form class="ry_form" v-show="showSearch" :inline="true" label-width="100px" :model="searchParams" ref="queryForm"
             size="medium">
      <el-form-item :label="$t('outBound.status')" prop="shipmentOrderStatus">
        <DictRadio v-model="searchParams.shipmentOrderStatus" :radioData="dict.type.wms_shipment_status" :showAll="'all'"
                   size="small" @change="handleQuery"></DictRadio>
      </el-form-item>
      <el-form-item :label="$t('outBound.OrderNo')" prop="shipmentOrderNo">
        <el-input v-model="searchParams.shipmentOrderNo" clearable="clearable" :placeholder="$t('common.pleaseInput')" size="small"
                  @keyup.enter.native="handleQuery"></el-input>
      </el-form-item>
      <el-form-item :label="$t('order.orderNo')" prop="orderNo">
        <el-input v-model="searchParams.orderNo" clearable="clearable" :placeholder="$t('common.pleaseInput')" size="small"
                  @keyup.enter.native="handleQuery"></el-input>
      </el-form-item>
      <el-form-item :label="$t('common.customer')" prop="customerId">
        <WmsCustomerSelect v-model="searchParams.customerId" size="small"></WmsCustomerSelect>
      </el-form-item>
      <el-form-item class="flex_one tr">
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">{{ $t('common.search') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('common.reset') }}</el-button>
      </el-form-item>
    </el-form>
    <el-table border v-loading="loading" :data="tableData" row-key="id" style="width: 100%"
      cell-class-name="table-cell-align-center">
      <el-table-column align="center" :label="$t('outBound.OrderNo')" prop="shipmentOrderNo"></el-table-column>
      <el-table-column align="center" :formatter="getCustomer" :label="$t('common.customer')"></el-table-column>
      <el-table-column align="center" :label="$t('order.orderNo')" prop="orderNo"></el-table-column>
      <el-table-column align="center" :label="$t('outBound.status')">
        <template slot-scope="scope">
          <el-tag effect="plain" size="medium" :type="getShipmentOrderStatusTag(scope.row)">
            {{ getShipmentOrderStatus(scope.row) }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column align="center" :label="$t('common.WaveNo')" prop="waveNo"></el-table-column>
      <el-table-column align="center" :label="$t('common.remark')" prop="remark">
        <template v-slot="{ row }">
          <el-popover placement="left" width="300" trigger="hover" :content="row.remark" popper-class="popperOptions">
            <p class="showOverTooltip" slot="reference">{{ row.remark }}</p>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <div style="text-align: right; margin-top: 10px">
      <el-pagination background @current-change="handleCurrent" @size-change="handleSizeChange"
        :page-sizes="[10, 20, 50, 100]" :page-size.sync="page.pageSize" :current-page.sync="page.pageNum"
        layout="total, sizes, prev, pager, next, jumper" :total="page.total"></el-pagination>
    </div>
  </div>
</template>
<script>
import {mapGetters} from 'vuex'
import { listWmsShipmentOrder } from '@/api/wms/shipmentOrder'
import {ShipmentOrderConstant} from '@/constant/ShipmentOrderConstant.ts'

export default {
  props: ["orderId"],
  dicts: ['wms_shipment_type', 'wms_shipment_status'],
  data() {
    return {
      // 查询参数
      searchParams: {
        shipmentOrderNo: null,
        customerId: null,
        orderNo: null,
        shipmentOrderStatus: null
      },
      queryParams: {
        name: "",
        orderId: null
      },
      tableData: [],
      page: {
        pageSize: 10,
        pageNum: 1,
        total: 0,
      },
      loading: false,
      showSearch: true
    };
  },
  computed: {
    ShipmentOrderConstant() {
      return ShipmentOrderConstant
    },
    shipmentStatusMap() {
      let obj = this.dict.type.wms_shipment_status.map(item => [item.value, item.label])
      let map = new Map(obj)
      return map
    },
    ...mapGetters(['customerMap']),
  },
  methods: {
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    getList() {
      this.loading = true;
      this.queryParams.orderId = this.orderId
      const query = {
        pageSize: this.page.pageSize,
        pageNum: this.page.pageNum,
        ...this.queryParams,
        ...this.searchParams
      };
      const pageReq = { page: this.page.pageNum - 1, size: this.page.pageSize }
      // console.log('query', query)
      // return
      listWmsShipmentOrder(query, pageReq).then(response => {
        console.log('res', response)
        const { content, totalElements } = response
        this.tableData = content || []
        this.page.total = totalElements
        this.loading = false
      })
    },
    getCustomer(row, column) {
      return this.customerMap.get(row.customerId)
    },
    getShipmentOrderStatusTag(row) {
      switch (row.shipmentOrderStatus) {
        case ShipmentOrderConstant.Status.NOT_IN:
          return 'info'
        case ShipmentOrderConstant.Status.PART_IN:
          return 'warning'
        case ShipmentOrderConstant.Status.DROP:
          return 'danger'
        case ShipmentOrderConstant.Status.ALL_IN:
          return 'success'
      }
    },
    getShipmentOrderStatus(row) {
      return this.shipmentStatusMap.get(row.shipmentOrderStatus + '')
    },
    handleCurrent(v) {
      this.page.pageNum = v;
      this.getList();
    },
    handleSizeChange(val) {
      this.page.pageSize = val;
      this.page.pageNum = 1;
      this.getList();
    },
    handleClick(v) {
      this.activeName = v;
      this.getList();
    },
    handleSeacrh(v) {
      this.queryParams = {
        ...v.filterForm,
        ...v.filterParam,
        name: v.fuzzySearch,
      };
      this.getList();
    },
  },
};
</script>
  